package br.edu.ufersa.scrumgame.mbean;

import java.util.GregorianCalendar;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import br.edu.ufersa.scrumgame.facade.DiaFacade;
import br.edu.ufersa.scrumgame.modelo.sistema.Dia;

@ManagedBean
@SessionScoped
public class DiaMBean {

	@EJB
	private DiaFacade diaFacade;
	
	private Dia dia = new Dia();
	
	private List<Dia> dias;
	
	public Dia getDia() {
		if( dia == null ) {
			dia = new Dia();
		}
		return dia;
	}

	public void setDia(Dia dia) {
		this.dia = dia;
	}
	
	public List<Dia> getDias() {
		dias = diaFacade.findAll();
		return dias;
	}
	
	public int getDiaAtual() {
		Dia dia = diaFacade.getDiaAtual();
		
		return dia.getDia();
	}

	public Long getTempoRestante() {
		Dia dia = diaFacade.getDiaAtual();
		GregorianCalendar gc = new GregorianCalendar();
		
		gc.setTime(dia.getInicio());
		gc.add(GregorianCalendar.MINUTE, 10);
		
		GregorianCalendar gcAtual = new GregorianCalendar();
		Long sec = ((gc.getTimeInMillis() - gcAtual.getTimeInMillis()) / 1000) / 60;
		
		return sec;
	}

}
